package edu.gdkm.dao;

import edu.gdkm.pojo.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ICourseDao {
    //2、查看课程列表接口（要求显示课程名称和教师名称）
    @Select("select * from t_course")
    @Results(id="coursewithteacher",value={
            @Result(
                    column = "tid",
                    property = "teacher",
                    one =@One(select = "edu.gdkm.dao.ITeacherDao.queryTeacherById")
            ),
            @Result(
                    column = "cid",
                    property = "studentList",
                    many = @Many(select="edu.gdkm.dao.IStudentDao.queryStudentByCid")
            )
    })
    public List<Course> queryCourse();
    //7、根据课程查看选课学生接口（显示学生姓名和学号）
    @Select("select * from t_course where cid = #{cid}")
    @ResultMap("coursewithteacher")
    public Course queryCourseById(Integer cid);

    @Select("select * from t_course where tid = #{tid}")
    public Course queryCourseByTid(Integer tid);

    //5、教师新增课程接口
    @Insert("insert into t_course values(null,#{coursename},#{teacher.tid})" )
    @Options(keyProperty = "cid",keyColumn = "cid",useGeneratedKeys = true)
    public Integer insertCourse(Course course);
}
